package studio7i.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import studio7i.excepcion.DAOExcepcion;
import studio7i.modelo.Instrumento;
import studio7i.modelo.Sala;
import studio7i.modelo.Local;
import studio7i.util.ConexionBD;

public class LocalDAO extends BaseDAO {
	
	

	
	public Collection<Local> listarLocales() throws DAOExcepcion {
		String query;
		
		Collection<Local> s = new ArrayList<Local>();
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		
		try {
			con = ConexionBD.obtenerConexion();
			query = "select * from local";
			stmt = con.prepareStatement(query);
			rs = stmt.executeQuery();
			
			while (rs.next()) {
					
					Local lo= new Local();
					lo.setIdLocal(rs.getInt("idLocal"));
					lo.setDescripcion(rs.getString("descripcion"));
					lo.setUbicacion(rs.getString("ubicacion"));
					lo.setDistrito(rs.getString("distrito"));
					s.add(lo);
					
				} 
			}catch (SQLException e) {
				System.err.println(e.getMessage());
				throw new DAOExcepcion(e.getMessage());
			} finally {
				this.cerrarStatement(stmt);
				this.cerrarConexion(con);
			}
			return s;	
	}
	

}
